package com.javaweb.controller;

import com.javaweb.controller.common.ResponseResult;
import com.javaweb.dto.UserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/11/2 16:41
 */

@RestController
@RequestMapping("/data")
@Slf4j
public class DataTransferController {

    @GetMapping("/param/simple")
//sat_chpt_04_springmvc/data/param/simple?erre=zhangsan&password=123456
    public String dataInQueryString(@RequestParam("realName") String username,
                                    String password) {
        log.info("username:{}, password:{}", username, password);
        return "ok";
    }

    @PostMapping("/param/form")
    public String dataInForm(@ModelAttribute UserDto userDto) {
        log.info("userDto:{}", userDto);
        return "ok";
    }

    @PostMapping("/param/json")
    /**
     *
     *    123    ->   123
     *    "hello"   ->  "hello"
     *    useDto(zhangsan, 123456)   ->
     *    {
     *      "username": "zhangsan",
     *      "password": "123456",
     *      "age": 18,
     *      "interests": ["music", "reading"]

     *    }
     *
     *   json序列化： 对象   -> json格式数据
     *   json反序列化： json格式数据  -> 对象
     *
     */
    public String dataInJson(@RequestBody UserDto userDto) {
        log.info("userDto:{}", userDto);
        return "ok";
    }
    @PostMapping("/resp/json")
    public ResponseResult<UserDto> dataJson(@RequestBody UserDto userDto) {
        log.info("userDto:{}", userDto);
        return ResponseResult.ok(userDto);
    }







}
